/*
* Copyright 2011 Pavel Kozhin 
*
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
* http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed  under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License.
*
* Author: Pavel Kozhin.
*/
package org.etherframework.core.reflection
{
	import flash.utils.Dictionary;

	public final class MetadataInfo
	{
		private var _definition:XML;
		private var _className:String;
		private var _metatags:Vector.<Metatag>;
		private var _classReference:Class;
		private var _constructorArgs:Vector.<Parameter>;
		private var _metatagsMap:Dictionary;
		
		public function MetadataInfo(definition:XML, className:String, 
									 metatags:Vector.<Metatag>, classReference:Class, 
									 constructorArgs:Vector.<Parameter>)
		{
			_definition = definition;
			_className = className;
			_metatags = metatags;
			_classReference = classReference;
			_constructorArgs = constructorArgs;
		}

		public function getMetatag(name:String):Metatag
		{
			if (!_metatags)
				return null;
			
			if (!_metatagsMap)
				_metatagsMap = new Dictionary();
			
			if (_metatagsMap[name] !== undefined)
				return _metatagsMap[name];
			
			for each (var item:Metatag in _metatags)
			{
				if (item.name == name)
				{
					_metatagsMap[name] = item;
					return item;
				}
			}
			
			_metatagsMap[name] = null;
			return null;
		}
		
		public function get classReference():Class { return _classReference; }
		public function get constructorArgs():Vector.<Parameter> { return _constructorArgs; }
		public function get metatags():Vector.<Metatag> { return _metatags; }
		public function get className():String { return _className; }
		public function get definition():XML { return _definition; }
	}
}